// pages/auth/index.js
import wxApi from "../../utils/wxApi"
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  //授权登陆
  clickuserinfo: async function (e) {
    console.log('登陆', e);

    try {
      //获取用户信息
      let {
        encryptedData,
        rawData,
        iv,
        signature
      } = e.detail;
      //获取code
      let {
        code
      } = await wxApi.login();
      let token = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo";
      console.log("........", token);
      wx.setStorageSync('token', token);
      //返回上层
      wx.navigateBack({
        delta: 1,
      })
    } catch (err) {
      console.log(err);
    }
  }


})